#include <string>
#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=17 lang=cpp
 *
 * [17] 电话号码的字母组合
 */

// @lc code=start
vector<string> mapper = {
    "", "", "abc", "def", "ghi", "jkl",
    "mno", "pqrs", "tuv", "wxyz"
};
class Solution {
public:
    vector<string> letterCombinations(string digits) {
        vector<string> res;
        if (digits.size() == 0) return res;
        dfs(0, "", digits, res);
        return res;
    }

    void dfs(int i, string input, const string & digit, vector<string> & res) {
        if (i == digit.size()) {
            res.push_back(input);
            return;
        }
        int index = digit[i] - '0';
        for (int j = 0; j < mapper[index].size(); j++) {
            input.push_back(mapper[index][j]);
            dfs(i + 1, input, digit, res);
            input.pop_back();
        }
    }

};
// @lc code=end

